package trip;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.GenerationType;

import org.springframework.format.annotation.DateTimeFormat;

@Entity
@Table(name = "PERSON")
public class Person {
	@Id
	@Column(name = "id")
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private long id;

	@Column(name = "first_name", nullable = false, length = 20)
	private String first_name;

	@Column(name = "last_name", nullable = false, length = 20)
	private String last_name;

	@Column(name = "middle_name", columnDefinition = "varchar(15) default ''", length = 15)
	private String middle_name;

	@Column(name = "phone_number", columnDefinition = "varchar(15) default ''", length = 15)
	private String phone_number;

	@Column(name = "email", nullable = false, unique = true, length = 40)
	private String email;

	@Column(name = "birth", nullable = false)
	@DateTimeFormat(pattern="yyyy-MM-dd")
	private Date birth;
	
	//constructors
	public Person() {};
	
	public Person(long id, String first_name, String last_name, String middle_name, String phone_number, String email, Date birth) {
		this.id = id;
		this.first_name = first_name;
		this.last_name = last_name;
		this.middle_name = middle_name;
		this.phone_number = phone_number;
		this.email = email;
		this.birth = birth;
	}
	
	//id
	public long getId() {
		return id;
	}

	public Person setId(long id) {
		this.id = id;
		return this;
	}

	//first_name
	public String getFirst_name() {
		return first_name;
	}

	public Person setFirst_name(String first_name) {
		this.first_name = first_name;
		return this;
	}

	//last_name
	public String getLast_name() {
		return last_name;
	}

	public Person setLast_name(String last_name) {
		this.last_name = last_name;
		return this;
	}

	//middle_name
	public String getMiddle_name() {
		return middle_name;
	}

	public Person setMiddle_name(String middle_name) {
		this.middle_name = middle_name;
		return this;
	}

	//phone_number
	public String getPhone_number() {
		return phone_number;
	}

	public Person setPhone_number(String phone_number) {
		this.phone_number = phone_number;
		return this;
	}
	//email
	public String getEmail() {
		return email;
	}

	public Person setEmail(String email) {
		this.email = email;
		return this;
	}
	
	//birth
	public Date getBirth() {
		return birth;
	}

	public Person setBirth(Date birth) {
		this.birth = birth;
		return this;
	}
	
	public boolean equals(Person person) {
		if (person == null)
			return false;
		if (this.id == person.id && 
			this.first_name.equalsIgnoreCase(person.first_name) &&
			this.last_name.equalsIgnoreCase(person.last_name) &&
			this.middle_name.equalsIgnoreCase(person.middle_name) &&
			this.phone_number.equalsIgnoreCase(person.phone_number) &&
			this.email.equalsIgnoreCase(person.email) &&
			this.birth.equals(person.birth))
			return true;
		else
			return false;
	}
}